package com.chensf.studydemo.common

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View

class TriangleView :View{
    private val paint:Paint = Paint()
    private val path = Path()
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attributeSet,
        defStyleAttr
    ){
        paint.style = Paint.Style.FILL
        paint.isAntiAlias = true
        paint.color = Color.parseColor("#F3F7FF")
    }

    override fun onDraw(canvas: Canvas) {
        val width = measuredWidth
        val height = measuredHeight
        path.moveTo(0f,0f)
        path.lineTo(width.toFloat(),0f)
        path.lineTo(width.toFloat(), height.toFloat())
        path.close()
        canvas.drawPath(path,paint)
    }
}